#include <iostream>
#include <queue>
#include <string>
#include <string.h>
using namespace std;

int T,n;
int visit[100000];
string k;

int check(string str)
{
	int x=0,len = str.length();
	for(int i=0;i<len;i++)
	{
		x = (x*10+str[i]-'0') % n;
	}
	return x;
}

void bfs()
{
	queue<string> q;
	q.push(k);
	while(!q.empty())
	{
		string next = q.front();q.pop();
		int yu = check(next);
		if(yu == 0)
		{
			cout<<next<<endl;
			return;
		}
		if(visit[yu]==0)
		{
			q.push(next+"0");
			q.push(next+k);
			visit[yu] = 1;
		}
	}
}

int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n>>k;
		memset(visit,0,sizeof(int)*100000);
		bfs();
	}
    return 0;
}
